package com.alasbusy.alasbusyapp.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import com.alasbusy.alasbusyapp.R;
import com.zhy.android.percent.support.PercentRelativeLayout;

/**
 * Created by Administrator on 2018/1/24.
 */

public class UpdateInfoDialog extends Dialog {

    private onNoOnclickListener noOnclickListener;//取消按钮被点击了的监听器
    private onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器
    private EditText iccard_ed;
    private PercentRelativeLayout send_card_sure;
    private PercentRelativeLayout send_card_close;
    private String EditTxt;


    /**
     * 设置确定按钮和取消被点击的接口
     */
    public interface onYesOnclickListener {
        public void onYesClick(String string);
    }

    public interface onNoOnclickListener {
        public void onNoClick();
    }

    /**
     * 设置取消按钮的显示内容和监听
     *
     * @param onNoOnclickListener
     */
    public void setNoOnclickListener(onNoOnclickListener onNoOnclickListener) {
        this.noOnclickListener = onNoOnclickListener;
    }

    /**
     * 设置确定按钮的显示内容和监听
     *
     * @param onYesOnclickListener
     */
    public void setYesOnclickListener(onYesOnclickListener onYesOnclickListener) {
        this.yesOnclickListener = onYesOnclickListener;
    }

    public UpdateInfoDialog(@NonNull Context context) {
        super(context, R.style.dialog_thremTransparent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.self_info_item);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        iccard_ed = (EditText) findViewById(R.id.iccard_ed);
        send_card_sure = (PercentRelativeLayout) findViewById(R.id.send_card_sure);
        send_card_close = (PercentRelativeLayout) findViewById(R.id.send_card_close);
    }

    public void setEditTxt(String str){
        EditTxt = str;
    }

    private void initData() {
        if(!TextUtils.isEmpty(EditTxt)) {
            iccard_ed.setText(EditTxt);
        }
    }

    private void initEvent() {
        send_card_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(iccard_ed.getText().toString())) {
                    if (yesOnclickListener != null) {
                        yesOnclickListener.onYesClick(iccard_ed.getText().toString());
                    }
                } else {
                    iccard_ed.setError("文本框不能为空.");
                }
            }
        });

        send_card_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noOnclickListener != null) {
                    noOnclickListener.onNoClick();
                }
            }
        });
    }

}
